const app = getApp();
import axios from "../../http/axios.js";
import {
  apiUserLogin,
} from "../../http/server.js";
import {
  commonGetNotice,
  commonToNoticeDetail
} from "../../assets/js/notice.js";
import getServiceList from "../../assets/js/service-list.js"

Page({
  data: {
    noList: {
      img: "/assets/img/zwjl.png",
      text: "暂无热门服务"
    },
    notice: [
      // {
      //   item: [{
      //       title: "公告1"
      //     },
      //     {
      //       title: "公告1"
      //     }
      //   ]
      // },
      // {
      //   item: [{
      //       title: "公告1"
      //     },
      //     {
      //       title: "公告1"
      //     }
      //   ]
      // }
    ], //健康公告
    bannerImg: "/assets/img/banner.png", //banner图片
    hotService: [
      // {
      //   id: 1,
      //   src: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1565785713630&di=1537bc03c22d0117a71c48b045d9cea7&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Ff603918fa0ec08fa3139e00153ee3d6d55fbda5f.jpg",
      //   title: "普通换药",
      //   description: "伤口清洁，换敷料"
      // },
      // {
      //   id: 2,
      //   src: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1565785713630&di=1537bc03c22d0117a71c48b045d9cea7&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Ff603918fa0ec08fa3139e00153ee3d6d55fbda5f.jpg",
      //   title: "打针",
      //   description: "肌肉注射，皮下注射"
      // }
    ]
  },
  onLoad: function(options) {
    this.userLogin();
    this.getNotice();
    this.getHotServicesList();
  },
  onShow: function() {},
  // 获取热门服务列表
  getHotServicesList: function() {
    getServiceList({
      page: 1,
      pageSize: 10
    }).then(res => {
      let hotService = [];
      res.records.forEach((item, index) => {
        let item1 = item;
        item1.title = item.name;
        item1.id = item.itemId; //唯一标识
        item1.src = item.image; //图片
        item1.description = item.description; //简短服务描述
        hotService.push(item1);
      })
      this.setData({
        hotService
      })
    })
  },
  // 获取公告
  getNotice: function() {
    let that = this;
    commonGetNotice(that);
  },
  // 跳转公告详情
  toNoticeDetail: function(e) {
    let item = e.detail;
    commonToNoticeDetail(item);
  },
  // 去院内护理
  handleClickToNursingInhospital: function() {
    wx.navigateTo({
      url: "/pages/u_serviceItemList/u_serviceItemList?nursingType=院内护理&title=院内护理",
    })
  },
  // 去护理上门页
  handleClickToNursingAtDoor: function() {
    wx.navigateTo({
      url: "/pages/u_serviceItemList/u_serviceItemList?nursingType=护理上门&title=护理上门",
    })
  },
  // 去选择医院
  tohosipital: function(e) {
    let detail = e.detail;
    let item = detail.item;
    let index = detail.index;
    // console.log(detail)
    // return;
    wx.navigateTo({
      // url: `/pages/u_serviceHospital/u_serviceHospital?serviceId=2&title=打针` //调接口时修改
      url: `/pages/u_serviceHospital/u_serviceHospital?serviceId=${item.id}&title=${item.title}` //调接口时修改
    })
  },
  // 用户登录
  userLogin: function() {
    let userInfo = wx.getStorageSync("userInfo");
    axios({
      url: apiUserLogin,
      data: {
        openid: userInfo.openid
      }
    }).then(res => {
      if (res && res.userType) {
        let userInfo = {
          ...res.user,
          userType: res.userType
        };
        wx.setStorageSync("userInfo", userInfo);
      }
    })
  }
})